package com.study.suanfa;

import java.util.Arrays;
import java.util.Scanner;
import java.util.Stack;

/**
 * @description: MoNiDuiLie   两个栈模拟队列
 * @date: 2020/11/25 0:32
 * @author: hcm
 * @version: 1.0
 */
public class MoNiDuiLie {

    public static void main(String[] args) {
        StackQueue queue = new StackQueue();
        queue.pushQueue(1);
        queue.pushQueue(2);
        queue.pushQueue(3);
        queue.pushQueue(4);
        queue.pushQueue(5);
        queue.popQueue();
    }

}

class StackQueue {
    /**
     * 双栈模拟队列
     */
    public Stack<Integer> stack1 = new Stack<Integer>();
    public Stack<Integer> stack2 = new Stack<Integer>();

    /**
     * 入第一个栈
     */
    public void pushQueue(int data) {
        stack1.push(data);
    }

    /**
     * 从第二个出栈
     */
    public void popQueue() {
        if (stack2.isEmpty()) {
            if (stack1.isEmpty()) {
                return;
            }
            dataToStack2();
        }
        System.out.println("队列大小"+stack2.size());
        System.out.println("出队");
        while (stack2.size() != 0) {
            System.out.println(stack2.pop());
        }

    }

    /**
     * 进入第二个栈
     */
    private void dataToStack2() {
        while (!stack1.isEmpty()) {
            //乾坤大挪移
            stack2.push(stack1.pop());
        }
    }

}
